//var gis = window.frames.gis;
//console.info(gis);
//console.info(window.frames);
var loading = document.querySelector("#loading");

var show = $(".panel-body");
var template = $(".panel-body>.item").remove();

var lng=0,lat=0;
var eData;

window.frames.gis.addEventListener("map-select",function(e){
	$("._lng").val(e.data.lng);
	$("._lat").val(e.data.lat);
	eData = e.data;
});

window.frames.gis.addEventListener("map-item",function(e){
	alert(e.index+":"+JSON.stringify(e.data));
});


var listPlayer = function(){
	if(eData==null){
		setTimeout(listPlayer,1000);
		return;
	}
	if(lng==eData.lng&&lat==eData.lat){
		setTimeout(listPlayer,1000);
		return;
	}
	loading.style.display="flex";
	lng = eData.lng;
	lat = eData.lat;
	$.get(
		"shops/near.do",
		{"lng":lng,"lat":lat,"r":0.2},
//		{"lng":lng,"lat":lat},
		function(data){
			if(data.ok){
				window.frames.gis.clear();
				show.empty();
				$.each(data.list, function(i,v) {
					window.frames.gis.add(v.shopName,v.point.x,v.point.y,v);
					let item = template.clone().appendTo(show);
					item.find(".title").text((i+1)+"."+v.shopName);
					item.find("img").attr("src",v.img[0]);
					item.find("._btn1").click(function(){
						window.frames.gis.setCenter(v.point.x,v.point.y);
					});
					
				});
			}else{
				toastr.error(data.message);
			}
			loading.style.display="none";
			setTimeout(listPlayer,1000);
		},"json"
	);
}
listPlayer();
